<template>
    <div class="payment-list-maintain">
        <!-- 筛选条件 -->
        <condition-card @search="filterCondition" @reset="reset">
            <el-row>
                <el-col :span="8">
                    <el-form-item label="年级">
                        <el-date-picker
                            style="width: 100%;"
                            v-model="query.grade"
                            type="year"
                            value-format="yyyy"
                            placeholder="请选择"
                            :picker-options="pickerOptions"
                            @change="currentManageDptId === '1' ? handleChangeFaculty() : ''"
                        ></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="学院">
                        <DictSelect
                            labelAll="请选择"
                            v-model="multipleQuery.faculty"
                            :data="options.faculty"
                            @change="handleChangeFaculty"
                            multiple
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="专业">
                        <DictSelect
                            labelAll="请选择"
                            v-model="multipleQuery.profession"
                            :data="options.profession"
                            multiple
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="培养层次">
                        <DictSelect
                            labelAll="请选择"
                            v-model="multipleQuery.trainingLevel"
                            :data="options.trainingLevel"
                            multiple
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="培养类别">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.trainingCategory"
                            :data="options.trainingCategory"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="学位类型">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.degreeType"
                            :data="options.degreeType"
                            @change="currentManageDptId !== '1' ? handleChangeFaculty() : ''"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="学习形式">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.formLearning"
                            :data="options.formLearning"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="维护类别">
                        <DictSelect
                            labelAll="请选择"
                            v-model="query.maintainCategory"
                            :data="options.maintainCategory"
                        ></DictSelect>
                    </el-form-item>
                </el-col>
            </el-row>
        </condition-card>
        <el-card shadow="never">
            <h2>应缴费名单维护列表</h2>
            <el-row type="flex" align="middle" class="mb-8px">
                <el-col class="text-left">
                    <KeywordInput
                        v-model="query.keyWord"
                        @enter="getPaymentList"
                        :placeholder="$t('score.failScoreManage.pleaseInt')"
                    ></KeywordInput>
                </el-col>
                <el-col class="text-right">
                    <!-- 隐藏上传按钮 -->
                    <el-upload
                        style="display: none;"
                        ref="importFile"
                        action="/api/studentservice/paymentlist/importPaymentList"
                        accept=".xlsx"
                        :file-list="importConfig.fileList"
                        :on-success="importFileSuccess"
                        :on-error="importFileError"
                        :on-change="importConfig.handlerChange"
                        :on-exceed="importConfig.handlerExceed"
                        :auto-upload="true"
                        :show-file-list="false"
                    >
                        <span slot="trigger" ref="upload">导入</span>
                    </el-upload>
                    <el-dropdown
                        trigger="click"
                        @command="handleCommand"
                        v-if="currentUid !== 'admin1'"
                    >
                        <el-button>
                            导入
                            <i class="el-icon-arrow-down el-icon--right"></i>
                        </el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item command="import">导入</el-dropdown-item>
                            <el-dropdown-item command="download">下载模板</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                    <el-button @click="exportFile">导出</el-button>
                    <template v-if="currentUid !== 'admin1'">
                        <el-button type="primary" @click="addPayment">新增</el-button>
                        <el-button type="danger" @click="batchDeletePayment">批量删除</el-button>
                    </template>
                </el-col>
            </el-row>
            <edu-table
                :order="false"
                :data="paymentListMaintain.data"
                :total="paymentListMaintain.total"
                :pageNum="query.pageNum_"
                @page-change="pageChange"
                @selection-change="handleSelectionChange"
            >
                <el-table-column label="学号">
                    <template slot-scope="scope">
                        {{ scope.row.studentId }}
                    </template>
                </el-table-column>
                <el-table-column label="姓名">
                    <template slot-scope="scope">
                        {{ scope.row.studentName }}
                    </template>
                </el-table-column>
                <el-table-column label="年级">
                    <template slot-scope="scope">
                        {{ scope.row.grade }}
                    </template>
                </el-table-column>
                <el-table-column label="学院" show-overflow-tooltip>
                    <template slot-scope="scope">
                        {{ scope.row.facultyI18n }}
                    </template>
                </el-table-column>
                <el-table-column label="专业" show-overflow-tooltip>
                    <template slot-scope="scope">
                        {{ scope.row.professionI18n }}
                    </template>
                </el-table-column>
                <el-table-column label="培养层次">
                    <template slot-scope="scope">
                        {{ scope.row.trainingLevelI18n }}
                    </template>
                </el-table-column>
                <el-table-column label="培养类别">
                    <template slot-scope="scope">
                        {{ scope.row.trainingCategoryI18n }}
                    </template>
                </el-table-column>
                <el-table-column label="学位类型">
                    <template slot-scope="scope">
                        {{ scope.row.degreeTypeI18n }}
                    </template>
                </el-table-column>
                <el-table-column label="学习形式">
                    <template slot-scope="scope">
                        {{ scope.row.formLearningI18n }}
                    </template>
                </el-table-column>
                <el-table-column label="维护类别">
                    <template slot-scope="scope">
                        {{ scope.row.maintainCategory | getMaintainCategory }}
                    </template>
                </el-table-column>
                <el-table-column label="操作" v-if="currentUid !== 'admin1'">
                    <template slot-scope="scope">
                        <el-button type="text" @click="editPayment(scope.row)">编辑</el-button>
                        <el-button type="text" @click="deletePayment(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </edu-table>
        </el-card>
        <!-- 新增、编辑界面 -->
        <edu-dialog
            ref="maintainDialog"
            title="应缴费名单维护"
            size="medium"
            @close="closeMaintainDialog"
            :auto-height="true"
        >
            <edu-dialog ref="innerDialog" title="提示" class="tip-item" append-to-body>
                返回将不会保存当前应收费设置，是否确定？
                <span slot="buttons">
                    <el-button @click="cancleDialog">取消</el-button>
                    <el-button type="primary" @click="confirmDialog">确定</el-button>
                    <el-button type="primary" @click="confirmAndSave">保存并关闭</el-button>
                </span>
            </edu-dialog>
            <el-form
                label-position="right"
                label-width="130px"
                ref="maintainForm"
                :model="maintainDialog.maintainForm"
                :rules="maintainDialog.rules"
            >
                <p>基础信息</p>
                <el-row>
                    <el-col :span="12">
                        <el-form-item
                            label="学号:"
                            prop="studentId"
                            :rules="[{ required: true, message: '学号不能为空', trigger: 'blur' }]"
                        >
                            <el-input
                                type="text"
                                v-model="maintainDialog.maintainForm.studentId"
                                @blur="getPaymentStuInfo(maintainDialog.maintainForm.studentId)"
                                placeholder="请输入学号"
                                :disabled="maintainDialog.type === 'edit' ? true : false"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="姓名:">
                            <el-input
                                type="text"
                                disabled
                                v-model="maintainDialog.maintainForm.studentName"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="年级:">
                            <GradeSelect
                                disabled
                                v-model="maintainDialog.maintainForm.grade"
                                :show-all="false"
                            ></GradeSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="学院:">
                            <DictSelect
                                labelAll="请选择"
                                :data="options.faculty"
                                disabled
                                v-model="maintainDialog.maintainForm.faculty"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="专业:">
                            <DictSelect
                                labelAll="请选择"
                                :data="maintainDialog.profession"
                                disabled
                                v-model="maintainDialog.maintainForm.profession"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="培养层次:">
                            <DictSelect
                                labelAll="请选择"
                                :data="options.trainingLevel"
                                v-model="maintainDialog.maintainForm.trainingLevel"
                                disabled
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="培养类别:">
                            <DictSelect
                                labelAll="请选择"
                                :data="options.trainingCategory"
                                v-model="maintainDialog.maintainForm.trainingCategory"
                                disabled
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="学位类型:">
                            <DictSelect
                                labelAll="请选择"
                                :data="options.degreeType"
                                v-model="maintainDialog.maintainForm.degreeType"
                                disabled
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="学习形式:">
                            <DictSelect
                                labelAll="请选择"
                                :data="options.formLearning"
                                v-model="maintainDialog.maintainForm.formLearning"
                                disabled
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="学制:">
                            <DictSelect
                                labelAll="请选择"
                                :data="options.lengthSchooling"
                                v-model="maintainDialog.maintainForm.lengthSchooling"
                                disabled
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
                <p>学年应缴费用信息设置</p>
                <el-row>
                    <el-col>
                        <el-form-item label="总应缴费用:" prop="sum">
                            <el-input
                                type="text"
                                v-model.number="maintainDialog.maintainForm.sum"
                                disabled
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <template v-if="maintainDialog.maintainForm.lengthSchooling">
                        <el-col
                            :span="12"
                            v-if="0.5 <= maintainDialog.maintainForm.lengthSchooling"
                        >
                            <el-form-item
                                label="第一学年第1学期"
                                prop="semester1"
                                :rules="[
                                    { required: true, message: '费用不能为空' },
                                    { type: 'number', message: '费用必须为数字' }
                                ]"
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester1"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="1 <= maintainDialog.maintainForm.lengthSchooling">
                            <el-form-item
                                label="第一学年第2学期"
                                prop="semester2"
                                :rules="
                                    maintainDialog.projId !== '1'
                                        ? [
                                              { required: true, message: '费用不能为空' },
                                              { type: 'number', message: '费用必须为数字' }
                                          ]
                                        : ''
                                "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester2"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col
                            :span="12"
                            v-if="1.5 <= maintainDialog.maintainForm.lengthSchooling"
                        >
                            <el-form-item
                                label="第二学年第1学期"
                                prop="semester3"
                                :rules="[
                                    { required: true, message: '费用不能为空' },
                                    { type: 'number', message: '费用必须为数字' }
                                ]"
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester3"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="2 <= maintainDialog.maintainForm.lengthSchooling">
                            <el-form-item
                                label="第二学年第2学期"
                                prop="semester4"
                                :rules="
                                    maintainDialog.projId !== '1'
                                        ? [
                                              { required: true, message: '费用不能为空' },
                                              { type: 'number', message: '费用必须为数字' }
                                          ]
                                        : ''
                                "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester4"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col
                            :span="12"
                            v-if="2.5 <= maintainDialog.maintainForm.lengthSchooling"
                        >
                            <el-form-item
                                label="第三学年第1学期"
                                prop="semester5"
                                :rules="[
                                    { required: true, message: '费用不能为空' },
                                    { type: 'number', message: '费用必须为数字' }
                                ]"
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester5"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="3 <= maintainDialog.maintainForm.lengthSchooling">
                            <el-form-item
                                label="第三学年第2学期"
                                prop="semester6"
                                :rules="
                                    maintainDialog.projId !== '1'
                                        ? [
                                              { required: true, message: '费用不能为空' },
                                              { type: 'number', message: '费用必须为数字' }
                                          ]
                                        : ''
                                "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester6"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col
                            :span="12"
                            v-if="3.5 <= maintainDialog.maintainForm.lengthSchooling"
                        >
                            <el-form-item
                                label="第四学年第1学期"
                                prop="semester7"
                                :rules="[
                                    { required: true, message: '费用不能为空' },
                                    { type: 'number', message: '费用必须为数字' }
                                ]"
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester7"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="4 <= maintainDialog.maintainForm.lengthSchooling">
                            <el-form-item
                                label="第四学年第2学期"
                                prop="semester8"
                                :rules="
                                    maintainDialog.projId !== '1'
                                        ? [
                                              { required: true, message: '费用不能为空' },
                                              { type: 'number', message: '费用必须为数字' }
                                          ]
                                        : ''
                                "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester8"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col
                            :span="12"
                            v-if="4.5 <= maintainDialog.maintainForm.lengthSchooling"
                        >
                            <el-form-item
                                label="第五学年第1学期"
                                prop="semester9"
                                :rules="[
                                    { required: true, message: '费用不能为空' },
                                    { type: 'number', message: '费用必须为数字' }
                                ]"
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester9"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="5 <= maintainDialog.maintainForm.lengthSchooling">
                            <el-form-item
                                label="第五学年第2学期"
                                prop="semester10"
                                :rules="
                                    maintainDialog.projId !== '1'
                                        ? [
                                              { required: true, message: '费用不能为空' },
                                              { type: 'number', message: '费用必须为数字' }
                                          ]
                                        : ''
                                "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester10"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col
                            :span="12"
                            v-if="5.5 <= maintainDialog.maintainForm.lengthSchooling"
                        >
                            <el-form-item
                                label="第六学年第1学期"
                                prop="semester11"
                                :rules="[
                                    { required: true, message: '费用不能为空' },
                                    { type: 'number', message: '费用必须为数字' }
                                ]"
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester11"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="6 <= maintainDialog.maintainForm.lengthSchooling">
                            <el-form-item
                                label="第六学年第2学期"
                                prop="semester12"
                                :rules="
                                    maintainDialog.projId !== '1'
                                        ? [
                                              { required: true, message: '费用不能为空' },
                                              { type: 'number', message: '费用必须为数字' }
                                          ]
                                        : ''
                                "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester12"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col
                            :span="12"
                            v-if="6.5 <= maintainDialog.maintainForm.lengthSchooling"
                        >
                            <el-form-item
                                label="第七学年第1学期"
                                prop="semester13"
                                :rules="[
                                    { required: true, message: '费用不能为空' },
                                    { type: 'number', message: '费用必须为数字' }
                                ]"
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester13"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="7 <= maintainDialog.maintainForm.lengthSchooling">
                            <el-form-item
                                label="第七学年第2学期"
                                prop="semester14"
                                :rules="
                                    maintainDialog.projId !== '1'
                                        ? [
                                              { required: true, message: '费用不能为空' },
                                              { type: 'number', message: '费用必须为数字' }
                                          ]
                                        : ''
                                "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester14"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col
                            :span="12"
                            v-if="7.5 <= maintainDialog.maintainForm.lengthSchooling"
                        >
                            <el-form-item
                                label="第八学年第1学期"
                                prop="semester15"
                                :rules="[
                                    { required: true, message: '费用不能为空' },
                                    { type: 'number', message: '费用必须为数字' }
                                ]"
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester15"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" v-if="8 <= maintainDialog.maintainForm.lengthSchooling">
                            <el-form-item
                                label="第八学年第2学期"
                                prop="semester16"
                                :rules="
                                    maintainDialog.projId !== '1'
                                        ? [
                                              { required: true, message: '费用不能为空' },
                                              { type: 'number', message: '费用必须为数字' }
                                          ]
                                        : ''
                                "
                            >
                                <el-input-number
                                    style="width: 100%;"
                                    v-model="maintainDialog.maintainForm.semester16"
                                    :precision="2"
                                    :step="0.1"
                                    :min="0"
                                    :controls="false"
                                    @input="getSum"
                                ></el-input-number>
                            </el-form-item>
                        </el-col>
                    </template>
                </el-row>
            </el-form>
            <span slot="buttons">
                <el-button @click="cancleMaintainDialog">返回</el-button>
                <el-button type="primary" @click="saveAndEdit">保存</el-button>
            </span>
        </edu-dialog>
        <!-- 删除提示界面 -->
        <edu-dialog ref="deleteDialog" class="tip-item" title="提示" @close="closeDelete">
            是否确定删除？
            <span slot="buttons">
                <el-button @click="cancleDelete">否</el-button>
                <el-button type="primary" @click="confirmDelete">是</el-button>
            </span>
        </edu-dialog>
    </div>
</template>
<script>
import { queryDic } from 'common/src/api/dictionary'
import UTILS from 'common/src/utils/utils'
import * as API from 'common/src/api/paymentManage'
export default {
    name: 'paymentListMaintain',
    components: {},
    data() {
        return {
            multipleQuery: {
                faculty: [],
                profession: [],
                trainingLevel: []
            },
            query: {
                grade: '',
                trainingLevel: '',
                faculty: '',
                profession: '',
                trainingCategory: '',
                degreeType: '',
                formLearning: '',
                maintainCategory: '',
                keyWord: '',
                pageNum_: 1,
                pageSize_: 20
            },
            options: {
                trainingLevel: [],
                faculty: [],
                profession: [],
                formLearning: [],
                degreeType: [],
                trainingCategory: [],
                maintainCategory: [
                    {
                        label: '系统维护',
                        value: '0'
                    },
                    {
                        label: '数据导入',
                        value: '1'
                    },
                    {
                        label: '手工维护',
                        value: '2'
                    }
                ],
                lengthSchooling: []
            },
            pickerOptions: {
                disabledDate(time) {
                    return (
                        time.getTime() > Date.now() || time.getTime() < new Date('1978').getTime()
                    )
                }
            },
            selectItems: [],
            paymentListMaintain: {
                total: 0,
                data: []
            },
            maintainDialog: {
                maintainForm: {
                    studentId: '',
                    studentName: '',
                    grade: '',
                    faculty: '',
                    profession: '',
                    trainingLevel: '',
                    trainingCategory: '',
                    degreeType: '',
                    formLearning: '',
                    lengthSchooling: '',
                    sum: '',
                    semester1: null,
                    semester2: null,
                    semester3: null,
                    semester4: null,
                    semester5: null,
                    semester6: null,
                    semester7: null,
                    semester8: null,
                    semester9: null,
                    semester10: null,
                    semester11: null,
                    semester12: null,
                    semester13: null,
                    semester14: null,
                    semester15: null,
                    semester16: null
                },
                isStudentId: true, // 判断学号输入是否符合条件 默认符合
                projId: null,
                rules: [],
                type: null,
                profession: [],
                semesterArr: []
            },
            deleteDialog: {
                deleteType: '', // "batch"和"single"
                deleteData: null
            },
            importConfig: {
                fileList: [],
                handlerChange(file, fileList) {
                    this.fileList.fileList = fileList.slice(-1)
                },
                handlerExceed(file, fileList) {
                    this.uploadConfig.fileList = fileList.slice(-1)
                }
            },
            currentManageDptId: '', // 当前部门
            currentUid: '' // 当前uid
        }
    },
    created() {
        this.initOptions()
        this.getPaymentList()
        // 获取当前部门和当前uid
        if (this.mockUser) {
            this.currentManageDptId = this.mockUser.currentManageDptId
            this.currentUid = this.mockUser.uid
        } else {
            this.currentManageDptId = this.currentUser.currentManageDptId
            this.currentUid = this.currentUser.uid
        }
    },
    mounted() {},
    methods: {
        // 获取筛选条件字段下拉数据
        initOptions() {
            const data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['X_YX', 'X_PYCC', 'X_PYLB', 'X_XWLX', 'X_XXXS', 'X_XZ']
            }
            queryDic(data).then(res => {
                if (res.code === 200) {
                    UTILS.fillSelect(
                        {
                            faculty: 'X_YX',
                            trainingLevel: 'X_PYCC',
                            trainingCategory: 'X_PYLB',
                            degreeType: 'X_XWLX',
                            formLearning: 'X_XXXS',
                            lengthSchooling: 'X_XZ'
                        },
                        res.data,
                        this.options
                    )
                }
            })
        },
        // 根据学院获取专业
        handleChangeFaculty(val) {
            this.options.profession = []
            this.query.profession = ''
            this.maintainDialog.profession = []
            let facultys, degreeType
            if (this.maintainDialog.type) {
                let maintainFaculty = this.maintainDialog.maintainForm.faculty
                let maintainDegreeType = this.maintainDialog.maintainForm.degreeType
                facultys = maintainFaculty ? [maintainFaculty] : []
                degreeType = maintainDegreeType ? [maintainDegreeType] : []
            } else {
                facultys = this.multipleQuery.faculty
                degreeType = this.query.degreeType ? [this.query.degreeType] : []
            }
            const data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: ['G_ZY'],
                filter: {
                    prefix: facultys,
                    specilaCode: 'XY2ZY',
                    facultys: facultys,
                    grade: this.query.grade,
                    degreeType: degreeType
                }
            }
            queryDic(data).then(res => {
                if (res.code === 200)
                    UTILS.fillSelect(
                        {
                            profession: 'G_ZY'
                        },
                        res.data,
                        this.options
                    )
                if (this.maintainDialog.type)
                    UTILS.fillSelect(
                        {
                            profession: 'G_ZY'
                        },
                        res.data,
                        this.maintainDialog
                    )
            })
        },
        // 重置
        reset() {
            let query = this.query
            for (var key in query) {
                if (key.includes('pageNum_')) {
                    query[key] = 1
                } else if (key.includes('pageSize_')) {
                    query[key] = 20
                } else if (!key.includes('keyWord')) {
                    query[key] = ''
                }
            }
            // 重置多选下拉数组
            let multipleQuery = this.multipleQuery
            for (var i in multipleQuery) {
                multipleQuery[i] = []
            }
            this.options.profession = []
            this.getPaymentList()
        },
        // 筛选
        filterCondition() {
            this.query.pageNum_ = 1
            this.getPaymentList()
        },
        // 新增
        addPayment() {
            this.$refs.maintainDialog.open()
            this.maintainDialog.type = 'add'
        },
        cancleMaintainDialog() {
            // 判断maintainForm是否有值
            let formData = this.maintainDialog.maintainForm
            let keys = Object.keys(formData).filter(item => {
                return formData[item]
            })
            let length = keys.length
            if (length) this.$refs.innerDialog.open()
            else this.$refs.maintainDialog.close()
        },
        // maintainDialog保存编辑提交数据
        saveAndEdit() {
            this.$refs.maintainForm.validate(valid => {
                if (valid) {
                    if (this.maintainDialog.type === 'add') {
                        if (this.maintainDialog.isStudentId) {
                            API.addPayment(this.maintainDialog.maintainForm).then(res => {
                                if (res.code === 200) {
                                    this.$message({
                                        type: 'success',
                                        message: '新增缴费名单成功'
                                    })
                                    this.getPaymentList()
                                    this.$refs.innerDialog.close()
                                    this.$refs.maintainDialog.close()
                                }
                            })
                        } else {
                            this.$message({
                                type: 'error',
                                message: '请检查学号是否正确'
                            })
                        }
                    } else if (this.maintainDialog.type === 'edit') {
                        API.updatePayment(this.maintainDialog.maintainForm).then(res => {
                            if (res.code === 200) {
                                this.$message({
                                    type: 'success',
                                    message: '编辑缴费名单成功!'
                                })
                                this.getPaymentList()
                                this.$refs.maintainDialog.close()
                                this.$refs.innerDialog.close()
                            }
                        })
                    }
                } else {
                    this.$refs.innerDialog.close()
                }
            })
        },
        // 关闭maintainDialog时触发
        closeMaintainDialog() {
            this.$refs.maintainForm.resetFields()
            this.maintainDialog.type = null
            this.maintainDialog.projId = null
            this.maintainDialog.isStudentId = true
            this.initMaintainForm()
            this.maintainDialog.maintainForm.studentId = ''
        },
        saveMaintainDialog() {
            // 保存数据处理
            this.$refs.maintainDialog.close()
        },
        // 根据学生id获取学生信息
        getPaymentStuInfo(val) {
            if (val && this.maintainDialog.type === 'add') {
                this.initMaintainForm()
                API.paymentStuInfo(val).then(res => {
                    if (res.code === 200 && res.data)
                        if (res.data.length) {
                            let item = res.data[0]
                            if (this.currentManageDptId === '1')
                                if (this.currentManageDptId === item.projId) {
                                    this.maintainDialog.projId = item.projId
                                    this.assignMaintainForm(item)
                                    this.getSum()
                                } else {
                                    this.$message({
                                        type: 'error',
                                        message: '请输入本科生学号'
                                    })
                                }
                            else {
                                if (this.currentManageDptId === item.projId) {
                                    this.maintainDialog.projId = item.projId
                                    this.assignMaintainForm(item)
                                    this.getSum()
                                } else {
                                    this.$message({
                                        type: 'error',
                                        message: '请输入研究生学号'
                                    })
                                }
                            }
                        } else {
                            this.$message({
                                type: 'error',
                                message: '请检查学号是否正确'
                            })
                            this.maintainDialog.isStudentId = false
                        }
                })
            }
        },
        // 给maintainForm赋值
        assignMaintainForm(item) {
            if (item) {
                this.maintainDialog.maintainForm.studentName = item.studentName
                this.maintainDialog.maintainForm.grade = item.grade
                this.maintainDialog.maintainForm.faculty = item.faculty
                // 获取学院下的专业
                this.handleChangeFaculty(item.faculty)
                this.maintainDialog.maintainForm.profession = item.profession
                this.maintainDialog.maintainForm.trainingLevel = item.trainingLevel
                this.maintainDialog.maintainForm.trainingCategory = item.trainingCategory
                this.maintainDialog.maintainForm.degreeType = item.degreeType
                this.maintainDialog.maintainForm.formLearning = item.formLearning
                this.maintainDialog.maintainForm.lengthSchooling = item.lengthSchooling
            }
        },
        // 初始化maintainForm
        initMaintainForm() {
            let formData = this.maintainDialog.maintainForm
            for (var key in formData) {
                if (key !== 'studentId') {
                    if (key.includes('semester')) {
                        formData[key] = null
                    } else {
                        formData[key] = ''
                    }
                }
            }
        },
        // 下载模板
        downloadTemplate() {
            let columns = [
                [
                    '学号',
                    '第1学年第一学期',
                    '第1学年第二学期',
                    '第2学年第一学期',
                    '第2学年第二学期',
                    '第3学年第一学期',
                    '第3学年第二学期',
                    '第4学年第一学期',
                    '第4学年第二学期',
                    '第5学年第一学期',
                    '第5学年第二学期',
                    '第6学年第一学期',
                    '第6学年第二学期',
                    '第7学年第一学期',
                    '第7学年第二学期',
                    '第8学年第一学期',
                    '第8学年第二学期'
                ]
            ]
            UTILS.exportAsXlsx(columns, '应缴费设置模板.xlsx')
        },
        // 导入文件
        handleCommand(command) {
            if (command && command === 'import') {
                this.$refs.upload.click()
            } else if (command && command === 'download') {
                this.downloadTemplate()
            }
        },
        // 文件导入成功
        importFileSuccess(response, file, fileList) {
            if (response.code === 200) {
                this.$message({
                    message: '导入成功！',
                    type: 'success'
                })
            } else {
                this.$alert(response.msg, '提示', {
                    confirmButtonText: '确定',
                    type: 'warning'
                })
            }
            this.getPaymentList()
            this.$refs.importFile.clearFiles()
        },
        // 文件导入失败
        importFileError(response, file, fileList) {
            this.$message({
                message: '上传失败,请稍后再试!',
                type: 'error'
            })
            this.$refs.importFile.clearFiles()
        },
        // 导出
        exportFile() {
            this.multipleQueryToString()
            let params = this.query && _.clone(this.query)
            params.hasOwnProperty('pageNum_') && delete params.pageNum_
            params.hasOwnProperty('pageSize_') && delete params.pageSize_
            // 选中用选中值未选中用列表值
            if (this.selectItems.length) {
                params.studentIds = this.selectItems.map(item => {
                    return item.studentId
                })
            } else {
                params.studentIds = []
            }
            API.exportPaymentList(params)
        },
        // 编辑
        editPayment(row) {
            this.handleChangeFaculty(row.faculty, 'edity')
            this.$refs.maintainDialog.open()
            this.maintainDialog.type = 'edit'
            this.maintainDialog.maintainForm.id = row.id
            this.maintainDialog.maintainForm.studentId = row.studentId
            this.maintainDialog.maintainForm = {
                id: row.id,
                studentId: row.studentId,
                studentName: row.studentName,
                grade: row.grade,
                faculty: row.faculty,
                profession: row.profession,
                trainingLevel: row.trainingLevel,
                trainingCategory: row.trainingCategory,
                degreeType: row.degreeType,
                formLearning: row.formLearning,
                lengthSchooling: row.lengthSchooling,
                sum: row.sum,
                semester1: row.semester1,
                semester2: row.semester2,
                semester3: row.semester3,
                semester4: row.semester4,
                semester5: row.semester5,
                semester6: row.semester6,
                semester7: row.semester7,
                semester8: row.semester8,
                semester9: row.semester9,
                semester10: row.semester10,
                semester11: row.semester11,
                semester12: row.semester12,
                semester13: row.semester13,
                semester14: row.semester14,
                semester15: row.semester15,
                semester16: row.semester16
            }
            this.maintainDialog.projId = row.projId
            // this.getPaymentStuInfo(row.studentId);
            // this.handleLengthSchoolingChange(row.lengthSchooling, row);
            this.getSum()
        },
        // 关闭删除界面时触发方法(赋值初始化)
        closeDelete() {
            this.deleteDialog = {
                deleteType: '',
                deleteData: null
            }
        },
        // 单条数据删除（删除按钮）
        deletePayment(row) {
            this.deleteDialog.deleteType = 'single'
            this.deleteDialog.data = row
            this.$refs.deleteDialog.open(row)
        },
        // 批量删除
        batchDeletePayment() {
            this.deleteDialog.deleteType = 'batch'
            this.deleteDialog.data = this.selectItems
            if (this.deleteDialog.data.length) {
                this.$refs.deleteDialog.open()
            } else {
                this.$message({
                    type: 'warning',
                    message: '请至少选择一条数据'
                })
            }
        },
        // 删除界面确认界面事件
        cancleDelete() {
            this.$refs.deleteDialog.close()
        },
        confirmDelete() {
            // 删除处理
            let data = this.deleteDialog.data
            let ids = ''
            if (this.deleteDialog.deleteType === 'batch') {
                ids = data.reduce((pre, curr, index) => {
                    pre += curr.id
                    if (index < data.length - 1) {
                        pre += ','
                    }
                    return pre
                }, ids)
            } else if (this.deleteDialog.deleteType === 'single') {
                ids = data.id
            }
            API.deletePayment({ ids: ids }).then(res => {
                if (res.code === 200) {
                    this.$message({
                        type: 'success',
                        message: '删除成功！'
                    })
                    this.getPaymentList()
                }
            })
            this.$refs.deleteDialog.close()
        },
        // 嵌套dialog事件 取消
        cancleDialog() {
            this.$refs.innerDialog.close()
        },
        // 嵌套dialog事件 确认
        confirmDialog() {
            this.$refs.innerDialog.close()
            this.$refs.maintainDialog.close()
        },
        // 嵌套dialog事件 确认并保存
        confirmAndSave() {
            // 保存数据处理
            this.saveAndEdit()
        },
        pageChange(val) {
            this.query.pageNum_ = +val.pageNum
            this.query.pageSize_ = +val.pageSize
            this.getPaymentList()
        },
        // 选中数据
        handleSelectionChange(val) {
            this.selectItems = val
        },
        // 处理multipleQuery数组转换为字符串
        multipleQueryToString() {
            if (this.multipleQuery.faculty.length)
                this.query.faculty = this.multipleQuery.faculty.join(',')
            else this.query.faculty = ''
            if (this.multipleQuery.profession.length)
                this.query.profession = this.multipleQuery.profession.join(',')
            else this.query.profession = ''
            if (this.multipleQuery.trainingLevel.length)
                this.query.trainingLevel = this.multipleQuery.trainingLevel.join(',')
            else this.query.trainingLevel = ''
        },
        // 获取应缴费名单数据
        getPaymentList() {
            this.multipleQueryToString()
            this.paymentListMaintain.total = 0
            this.paymentListMaintain.data = []
            this.query.projId = this.currentManageDptId || ''
            API.list(this.query).then(res => {
                if (res.code === 200 && res.data) {
                    this.paymentListMaintain.total = res.data.total_
                    this.paymentListMaintain.data = res.data.list
                }
            })
        },
        // 计算总应缴费用
        getSum(val) {
            let formData = this.maintainDialog.maintainForm
            let semesterArr = []
            for (var key in formData) {
                if (key.includes('semester') && formData[key]) {
                    semesterArr.push(formData[key])
                }
            }
            let sum = 0
            sum = semesterArr.reduce((pre, curr, index) => {
                sum = pre + +curr
                return sum
            }, sum)
            sum = sum.toFixed(2)
            this.$set(this.maintainDialog.maintainForm, 'sum', sum)
        }
    },
    // 用来过滤维护类别
    filters: {
        getMaintainCategory(val) {
            let type = ''
            switch (val) {
                case '0':
                    type = '系统维护'
                    break
                case '1':
                    type = '数据导入'
                    break
                case '2':
                    type = '手工维护'
                    break
                default:
                    type
            }
            return type
        }
    },
    computed: {
        currentUser() {
            if (this.$store.state.session.user) {
                return this.$store.state.session.user
            }
            return JSON.parse(localStorage.getItem('user'))
        },
        mockUser() {
            if (this.$store.state.session.mockUser) {
                return this.$store.state.session.mockUser
            }
            return JSON.parse(localStorage.getItem('sessiondata')).mockUser
        }
    }
}
</script>
<style lang="scss" scoped>
.payment-list-maintain {
}
</style>
<!-- 覆盖element样式 -->
<style lang="scss">
.payment-list-maintain {
    .el-input-number.is-without-controls .el-input__inner {
        padding-right: 8px !important;
        padding-left: 8px !important;
        text-align: left;
    }
}
</style>
